package com.yiaik.base.task.scheduling;

import com.yiaik.base.bean.ResUser;
import com.yiaik.base.bean.ResultData;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.text.SimpleDateFormat;
import java.util.Date;

@Slf4j
@Component
public class ScheduledTasks {
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
    private final RestTemplate restTemplate;

    public ScheduledTasks(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @Scheduled(fixedRate = 1000)
    public void reportCurrentTime() {
        log.info("The time is now {}", dateFormat.format(new Date()));
        String url = "http://localhost:8010/app/user/login";
        ResUser params = ResUser.builder().id(2L).username("weihua").build();
        log.info("params:{}", params);
        ResultData<ResUser> result = restTemplate.postForObject(url, params, ResultData.class);
        log.info("restTemplate result: {}", result);
    }
}
